﻿app.service("BaseSrv", function ($http,$rootScope) {
    this.ShowError = function (response) {
        $rootScope.errors = response.data.Errors;
        $('#ErrModal').modal('show');
    };

    this.ShowConfirm = function (obj) {
        var objConfirm = { Mess: "Bạn muốn xóa đối tượng?", ConfirmClicked: false, Size:"modal-sm" };

        if (obj.hasOwnProperty("Mess")) {
            objConfirm.Mess = obj.Mess;
        }

        if (obj.hasOwnProperty("Size")) {
            objConfirm.Size = obj.Size;
        }

        $rootScope.objConfirm = objConfirm;
        $('#confirmModal').modal('show');
    }

    this.CloseModal = function (nameModal) {
        $(nameModal).modal('hide');
    };

    this.updateObject= function(srcObj, destObj) {
        for (var key in destObj) {
            if (destObj.hasOwnProperty(key) && srcObj.hasOwnProperty(key)) {
                destObj[key] = srcObj[key];
            }
        }
    }

    // Save(Add and Update) 
    this.ViewPage = function (nameView) {
        var response = $http({
            method: "post",
            url:"Home/ViewPage",
            data: { 'id': nameView },
        });
        return response;
    }
});